package com.relytosoft.mizar.media.common.utils;

import cn.hutool.core.util.StrUtil;
import com.relytosoft.mizar.media.common.constant.SymbolConstants;

import java.time.LocalDateTime;

/**
 * @author wss
 * @version 1.0
 * @date 2022/5/23 14:06
 */
public class DateUtil {
    private static final String DEFAULT_TIME_PATTERN = "HHmmss";

    /**
     * 获取当前时间的 时分秒字符串格式
     *
     * @param timePattern
     * @return
     */
    public static String toTimeStr(String timePattern) {
        if (StrUtil.isBlank(timePattern)) {
            timePattern = DEFAULT_TIME_PATTERN;
        }
        return cn.hutool.core.date.DateUtil.format(LocalDateTime.now(), timePattern);
    }

    /**
     * 获取当前天星期第几天
     * MONDAY --->1   SUNDAY --->7
     *
     * @return
     */
    public static int thisDayOfWeek() {
        int dayOfWeek = cn.hutool.core.date.DateUtil.thisDayOfWeek();
        int i = dayOfWeek - 1;
        if (i == 0) {
            return 7;
        }
        return i;
    }


    /**
     * 将形如13:32 这样的日期格式转为1332
     *
     * @param timeStr
     * @return
     */
    public static Long toHourMinute(String timeStr) {
        String s = StrUtil.removeAny(timeStr, SymbolConstants.COLON);
        return Long.valueOf(s);
    }

    /**
     * 获取当前日期的小时分钟格式
     * 形如1230
     *
     * @return
     */
    public static Long getHourMinute() {
        String thisHour = String.valueOf(cn.hutool.core.date.DateUtil.thisHour(true));
        String thisMinute = String.valueOf(cn.hutool.core.date.DateUtil.thisMinute());
        return Long.parseLong(StrUtil.fillAfter(thisHour + thisMinute, '0', 4));
    }


}
